package com.emode.action;

import java.util.List;

import com.emode.base.BaseAction;
import com.emode.entity.SysPrivilege;
import com.opensymphony.xwork2.ActionContext;

public class PriviAction extends BaseAction<SysPrivilege>{

	/**
	 * 
	 */
	private static final long serialVersionUID = 3107282040983440878L;
	private int parentId;
	
	public String priviList(){
		List<SysPrivilege> list = privilegeservice.findAll();
		ActionContext.getContext().put("list", list);
		ActionContext.getContext().put("privi", list);
		//ActionContext.getContext().getValueStack().push(list);
		return "prilist";
	}
	
	/*
	 * 添加权限  
	 */
	
	public String addPrivi(){
		if(!("").equals(parentId)||parentId!=0){
			model.setParentid(privilegeservice.getById(parentId));
		}
		
		privilegeservice.save(model);
		return "toprilist";
	}
	//这里应该可以返回boolean类型的，当没有删除成功可以返回false
	public String deletePrivi(){
		if(!("").equals(parentId)||parentId!=0){
			System.out.println(model.getPid());
			privilegeservice.deleteByIds(model.getPid());;
		}
		return "toprilist";
		
	}
	
	public String updatePrivi() throws Exception{
		System.out.println(""+parentId);
		SysPrivilege p = new SysPrivilege();
		p.setPid(parentId);
		if(parentId==0){
			model.setParentid(null);;
		}else{
		model.setParentid(p);
		}
		privilegeservice.update(model);
		
		return "toprilist";
	}

	public int getParentId() {
		return parentId;
	}

	public void setParentId(int parentId) {
		this.parentId = parentId;
	}


	

}
